<!--丢单-->
<template>
    <el-dialog v-model="dialogShow" :title="title" width="600px" :append-to-body="false"
               :close-on-click-modal="false" :close-on-press-escape="false">
        <el-form ref="dialogForm" :model="formInfo" :rules="rules" label-width="90px" label-position="left">
            <el-form-item label="客户名称" prop="customerName">
                <el-input v-model="formInfo.customerName" :style="formItemWidth"></el-input>
            </el-form-item>
            <el-form-item label="备注">
                <el-input v-model="formInfo.remark" :row="3" type="textarea" style="width: 98%"/>
            </el-form-item>
        </el-form>
        <template #footer>
            <el-button type="primary" @click="submit">提 交</el-button>
            <el-button @click="closeDialog">取 消</el-button>
        </template>
    </el-dialog>
</template>

<script setup name="addEditDialog">
    import setting from '../setting'
    const {proxy} = getCurrentInstance()

    const emit = defineEmits(['update:show', 'update:data'])


    const inject1 = inject('provideHTable')

    const props = defineProps({
        show: {
            type: Boolean,
            required: false,
            default: false
        },
        title: {
            type: String,
            required: false,
            default: '新增'
        },
        data: {
            type: Object,
            required: true,
            default: () => {
            }
        }
    })

    const formItemWidth = ref('width:200px')
    const rules = ref(setting.rules)

    let dialogShow = computed({
        get() {
            return props.show
        },
        set(val) {
            console.log('dialogShow', val)
            emit('update:show', val)
        }
    })

    let formInfo = computed({
        get() {
            return props.data
        },
        set(val) {
            emit('update:data', val)
        }
    })

    watch(() => dialogShow, val => {
        if (val === true) {
            console.log('dialogShow', dialogShow)
        }
    }, {immediate: false})

    onMounted(() => {

    })


    const submit = () => {
        let _ = proxy
        _.$refs["dialogForm"].validate(async valid => {
            if (!valid) return
            if (_.$V.isEmpty(formInfo.value.cmCustomerId)) {
                console.log('新增')
                // const {data: res} = await _.$H.post(_.$A.customer.add, formInfo.value)
                // if (res.code === 200) {
                //     _.$M.msgSuccess('新增成功！')
                //     inject1()
                //     closeDialog()
                // } else {
                // }
            } else {
                console.log('修改')
                // const {data: res} = await _.$H.post(_.$A.customer.edit, formInfo.value)
                // if (res.code === 200) {
                //     _.$M.msgSuccess('修改成功！')
                //     inject1()
                //     closeDialog()
                // } else {
                // }
            }
        })
    }
    const closeDialog = () => {
        let _ = proxy
        formInfo.value = {}
        _.resetForm("dialogForm")
        dialogShow.value = false
    }
</script>

<style lang="scss" scoped>
</style>
